import { Empty } from "antd";
import DetailEditor from "./Detail.editor";
import DetailText from "./Detail.text";
import DetailRoute from "./Detail.route";
// css
import styles from "@/styles/CommonDetail.module.scss";

// 高阶组件，包裹一层title
function DetailWrap(Comp) {
  return (
    <div className={styles["detail"]} id="anchor-detail">
      <h1 className={styles["common-title"]}>
        <span className="iconfont icon-tuwenxiangqing"></span> 产品详情
      </h1>
      {Comp}
    </div>
  );
}

export default function DetailEntry({ data, target }) {
  // data = null
  // 无数据
  if (!data || !data.length || (data.length === 1 && !data[0].value)) {
    return DetailWrap(
      <section>
        <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无产品内容" />
      </section>
    );
  }

  // 判断详情数据结构
  if (data.length === 1 && data[0].type === "timeAxis") {
    return DetailWrap(<DetailRoute data={data} />);
  } else if (data.length === 1 && (data[0].type === "null" || !data[0].type)) {
    // 攻略、目的地
    if (target === "/guide" || target === "/destination") {
      return <DetailEditor data={data} />;
    }
    return DetailWrap(<DetailEditor data={data} />);
  } else {
    // 攻略、目的地
    if (target === "/guide" || target === "/destination") {
      return <DetailText data={data} />;
    }
    return DetailWrap(<DetailText data={data} />);
  }
}
